class Calculate {
  add(a, b, precision = 6) {
    const factor = Math.pow(10, precision)
    return (Math.round(a * factor) + Math.round(b * factor)) / factor
  }

  desc(a, b, precision = 6) {
    const factor = Math.pow(10, precision)
    return (Math.round(a * factor) - Math.round(b * factor)) / factor
  }

  mul(a, b, precision = 6) {
    const factor = Math.pow(10, precision)
    const div_factor = factor * factor
    return (Math.round(a * factor) * Math.round(b * factor)) / div_factor
  }

  div(a, b, precision = 6) {
    const factor = Math.pow(10, precision)
    const result = Math.round(a * factor) / Math.round(b * factor)
    return Math.round(result * 1000000) / 1000000
  }
}

const calculate = new Calculate()

export default calculate
